package com.tyl.controller;

import com.tyl.pojo.Employee;
import com.tyl.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
// @RequestMapping("/Employee")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    //返回列表页
    @RequestMapping("/emps")
    public String lit(Model model){
        List<Employee> employees = employeeService.queryAllEmployeeList();
        model.addAttribute("emps",employees);
        return "emp/list";
    }


    @ResponseBody
    @GetMapping("queryAllEmployeeList")
    public List<Employee> queryAllEmployeeList(){
        return employeeService.queryAllEmployeeList();
    }

    @ResponseBody
    @GetMapping("queryEmployeeListById")
    public Employee queryEmployeeListById(int Id){
        return employeeService.queryEmployeeListById(Id);
    }

    @ResponseBody
    @PostMapping("addEmployee")
    public int addEmployee(Employee employee){
        return employeeService.addEmployee(employee);
    }

    @ResponseBody
    @PostMapping("deleteEmployee")
    public int deleteEmployee(int Id){
        return employeeService.deleteEmployee(Id);
    }

    // @ResponseBody
    // @PostMapping("updateEmployee")
    // public int updateEmployee(Employee employee){
    //     return  employeeService.updateEmployee(employee);
    // }
}
